 package uk.co.mmscomputing.concurrent;
 
 public class SignalBlockingQueue extends ArrayBlockingQueue
 {
   public SignalBlockingQueue(int paramInt)
   {
     super(paramInt);
   }
 
   public Object take() throws InterruptedException
   {
     this.full.acquire();
     Object localObject1;
     synchronized (this.gt) {
       localObject1 = this.buffer[this.front];
       this.front += 1; if (this.front >= this.size) { this.front -= this.size; this.fcarry = (!this.fcarry);
       }
     }
     return localObject1;
   }
 
   public Object poll(long paramLong, TimeUnit paramTimeUnit) throws InterruptedException {
     Object localObject1 = null;
     if (this.full.tryAcquire(paramLong, paramTimeUnit)) {
       synchronized (this.gt) {
         localObject1 = this.buffer[this.front];
         this.front += 1; if (this.front >= this.size) { this.front -= this.size; this.fcarry = (!this.fcarry);
         }
       }
     }
     return localObject1;
   }
 
   public void signal() {
     this.empty.release();
   }
   public int getPutIndex() {
     return this.rear; } 
   public int getTakeIndex() { return this.front; } 
   public Object getObjectAtIndex(int paramInt) { return this.buffer[paramInt]; }
 
   public void acquireWhenEmpty() throws InterruptedException {
     boolean bool;
     do {
       this.empty.acquire();
       bool = isEmpty();
       this.empty.release();
     }while (!bool);
   }
 
   public void clear() {
     while (poll() != null) signal();
   }
 }

